#!/bin/sh
# 指定要查找的目录
dir=$1
#指定最大文件数
limit_file_num=$2

total_file_num=$(ls $dir |wc -l);

#remove the earliest file
if [ "$total_file_num" -gt "$limit_file_num" ]
        then
        del_num=$((total_file_num-limit_file_num))
        echo "dir " ${dir}
	echo "del num is: " ${del_num}
        ls -ltr ${dir}/* | grep -v 'total' | awk '{print $9}' | head -n $del_num | xargs rm
fi
